package com.example.cushion.binddata;

import android.app.Activity;
import android.text.TextUtils;

import com.example.cushion.App;
import com.example.cushion.bean.MyMenuItem;
import com.example.cushion.global.SpKey;

import org.itzheng.and.baseutils.common.Language;
import org.itzheng.and.baseutils.common.LanguageUtils;
import org.itzheng.and.baseutils.common.SPUtils;
import org.itzheng.and.baseutils.log.LogHelper;
import org.w3c.dom.Text;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

/**
 * Title:<br>
 * Description: <br>
 *
 * @email ItZheng@ZoHo.com
 * Created by itzheng on 2018-3-8.
 */
public class DataSettingLanguage {
    private static final String TAG = "DataSettingLanguage";

    public static List<MyMenuItem> getLanguages(Activity activity) {
        List<MyMenuItem> items = new ArrayList<>();
        MyMenuItem item = null;
        //
        List<Language> languages = getLanguage();
        Locale locale = LanguageUtils.getCurrentAppLocale(App.getInstance());
        boolean isAuto = false;
        for (int i = 0; i < languages.size(); i++) {
            Language language = languages.get(i);
            item = new MyMenuItem();
            item.type = MyMenuItem.TYPE_RADIO_BUTTON;
            item.name = language.language;
            item.tag = language.locale;
            if (i == 0) {
                String s = SPUtils.getString(SpKey.STRING_APP_LANGUAGE, "");
                isAuto = TextUtils.isEmpty(s);
                item.setStatus(isAuto);
            } else if (!isAuto) {
                //如果当前不是自动
                item.setStatus(LanguageUtils.isEquals(locale, language.locale));
                LogHelper.d(TAG, "locale" + locale + ":" + " language.locale" + language.locale
                        + ":" + LanguageUtils.isEquals(locale, language.locale));
            }
            items.add(item);
        }


        return items;
    }

    public static List<Language> getLanguage() {
        List<Language> items = new ArrayList<>();
        items.add(Language.auto());
//        items.add(Language.ENGLISH_US);
        items.add(Language.ENGLISH);
        items.add(Language.CHINESE_CN);
        items.add(Language.CHINESE_TW);
        return items;
    }
}
